/*
 * hd_principal.java
 * 
 *  LICENÇA CC-GNU LGPL
 * 
 * EXCLUSÃO DE GARANTIA 
1.COMO A BIBLIOTECA É LICENCIADA ELA TERÁ TOTAL GARANTIA DE SUPORTE TÉCNICO,
  MAS CASO O CÓDIGO-FONTE SOFRA ALTERAÇÕES, NÃO HAVERÁ NENHUMA GARANTIA PARA A 
  BIBLIOTECA, NO LIMITE PERMITIDO PELA LEI APLICÁVEL. EXCETO QUANDO DE OUTRA FORMA
  ESTABELECIDO POR ESCRITO, OS TITULARES DOS DIREITOS AUTORAIS E/OU OUTRAS PARTES 
  FORNECEM A BIBLIOTECA "NO ESTADO EM QUE SE ENCONTRA", SEM NENHUMA GARANTIA DE 
  QUALQUER TIPO, TANTO EXPRESSA COMO IMPLÍCITA, INCLUINDO, DENTRE OUTRAS, AS GARANTIAS
  IMPLÍCITAS DE COMERCIABILIDADE E ADEQUAÇÃO PARA UMA FINALIDADE ESPECÍFICA. 
  O RISCO INTEGRAL QUANTO À QUALIDADE E DESEMPENHO DA BIBLIOTECA É ASSUMIDO POR VOCÊ.
  CASO A BIBLIOTECA CONTENHA DEFEITOS, VOCÊ ARCARÁ COM OS CUSTOS DE TODOS OS SERVIÇOS,
  REPAROS OU CORREÇÕES NECESSÁRIAS. 

 2.EM NENHUMA CIRCUNSTÂNCIA, A MENOS QUE EXIGIDO PELA LEI APLICÁVEL OU ACORDADO POR 
   ESCRITO, QUALQUER TITULAR DE DIREITOS AUTORAIS OU QUALQUER OUTRA PARTE QUE POSSA 
   MODIFICAR E/OU REDISTRIBUIR A BIBLIOTECA, CONFORME PERMITIDO ACIMA, SERÁ RESPONSÁVEL 
   PARA COM VOCÊ POR DANOS, INCLUINDO ENTRE OUTROS QUAISQUER DANOS GERAIS, ESPECIAIS, 
   FORTUITOS OU EMERGENTES, ADVINDOS DO USO OU IMPOSSIBILIDADE DE USO DA BIBLIOTECA 
   (INCLUINDO, ENTRE OUTROS, PERDA DE DADOS, DADOS SENDO GERADOS DE FORMA IMPRECISA, 
   PERDAS SOFRIDAS POR VOCÊ OU TERCEIROS OU A IMPOSSIBILIDADE DA BIBLIOTECA DE OPERAR 
   COM QUALQUER OUTRO SOFTWARE), MESMO QUE ESSE TITULAR, OU OUTRA PARTE, TENHA SIDO 
   AVISADO SOBRE A POSSIBILIDADE DESSES DANOS.
 *
 * Created on 20 de Janeiro de 2009, 17:32
 */

package cadastros;

import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import principal.tela_principal;
import relatorios.rel_help;
import utilitarios.conexao;
//import utilitarios.systray;

/**
 *
 * @author  Shinigami
 */
public class hd_principal extends javax.swing.JFrame {
   
 public static conexao con_hdserver, con_fecha;
 
 conexao con_server, con_servf, con_aberto, con_pesq, con_atual,con_user;
 final SystemTray tray = SystemTray.getSystemTray();; 
 Image image = Toolkit.getDefaultToolkit().getImage("/imagens/help-faq.png");
 final TrayIcon trayIcon ; 
 PopupMenu popup = new PopupMenu();
 MenuItem defaultItem = new MenuItem("Exit");
int cont = 0;
int linhas = 0;
 
 String acesso;   
 String seta_look = "com.birosoft.liquid.LiquidLookAndFeel";
 String usuario = tela_principal.lbusuario.getText();
 
    private ActionEvent e;
    /** Creates new form hd_principal */
    public hd_principal() {
        initComponents();
        con_server = new conexao();
        con_server.conecta();
        con_servf = new conexao();
        con_servf.conecta();
        con_aberto = new conexao();
        con_aberto.conecta();
        con_pesq = new conexao();
        con_pesq.conecta();
        con_atual = new conexao();
        con_atual.conecta();
        con_user = new conexao();
        con_user.conecta();
        con_fecha = new conexao();
        con_fecha.conecta();
        
        tela_principal.bt_helps.setEnabled(false);
        tela_principal.lb_helps.setVisible(false);
        tela_principal.jm_helps.setEnabled(false);        
        
        
        con_hdserver = new conexao();
        con_hdserver.conecta();
        
        trayIcon = new TrayIcon(image, "HelpDesk!", popup);      
        
        con_server.executasql("select * from helpdeska order by status , codurgencia , ordem");
        lookandfeel();
        preencher_tabela();
        stray();
        timer1.start();
        timer2.start();
        lb_tec.setText(usuario);
    
        
    
        
        
        
        
    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        timer2 = new org.netbeans.examples.lib.timerbean.Timer();
        jScrollPane1 = new javax.swing.JScrollPane();
        tb_fechado = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tb_aberto = new javax.swing.JTable();
        bt_visu = new javax.swing.JButton();
        bt_mostra = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        bt_atualiza = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        lb_tec = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jm_voltar = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();

        timer1.setDelay(60000L);
        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        timer2.setDelay(300000L);
        timer2.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer2OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("HelpDesk Server");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowDeiconified(java.awt.event.WindowEvent evt) {
                formWindowDeiconified(evt);
            }
            public void windowIconified(java.awt.event.WindowEvent evt) {
                formWindowIconified(evt);
            }
        });

        tb_fechado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Nº", "Setor", "Máquina", "Tipo Problema", "Usuário", "Data"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tb_fechado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tb_fechadoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tb_fechado);

        tb_aberto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Nº", "Setor", "Máquina", "Tipo Problema", "Status", "Urgência", "Ordem"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tb_aberto);

        bt_visu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/stellarium.png"))); // NOI18N
        bt_visu.setToolTipText("Visualizar Chamada Aberta (F3)");
        bt_visu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_visuActionPerformed(evt);
            }
        });

        bt_mostra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Sherlock.png"))); // NOI18N
        bt_mostra.setToolTipText("Pesquisar (F4)");
        bt_mostra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_mostraActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setText("Chamados Abertos e Fechados");

        bt_atualiza.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/gnome-panel-clock.png"))); // NOI18N
        bt_atualiza.setToolTipText("Atualizar (F5)");
        bt_atualiza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_atualizaActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/TrashIcon.png"))); // NOI18N
        jButton1.setToolTipText("Limpar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lb_tec.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Técnico", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

        jMenu1.setText("Arquivo");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
        jMenuItem1.setText("Visualizar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        jMenuItem2.setText("Atualizar");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator1);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
        jMenuItem3.setText("Fechados");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);
        jMenu1.add(jSeparator2);

        jm_voltar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F8, 0));
        jm_voltar.setText("Tela Principal");
        jm_voltar.setEnabled(false);
        jm_voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jm_voltarActionPerformed(evt);
            }
        });
        jMenu1.add(jm_voltar);
        jMenu1.add(jSeparator3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F12, 0));
        jMenuItem4.setText("Sair");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Relatórios");

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, 0));
        jMenuItem5.setText("Chamadas Abertas");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F7, 0));
        jMenuItem6.setText("Gerar Relatórios");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(44, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane2)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bt_visu, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(bt_atualiza, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(bt_mostra, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(126, 126, 126))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lb_tec, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lb_tec, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_visu, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_atualiza, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE))
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_mostra, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-664)/2, (screenSize.height-468)/2, 664, 468);
    }// </editor-fold>//GEN-END:initComponents

private void bt_mostraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_mostraActionPerformed

    new pesq_helpf().setVisible(true);
        
    /*con_servf.executasql("select * from helpdeskf");
    
    tb_fechado.getColumnModel().getColumn(0).setPreferredWidth(50);
    tb_fechado.getColumnModel().getColumn(1).setPreferredWidth(150);
    tb_fechado.getColumnModel().getColumn(2).setPreferredWidth(50);
    tb_fechado.getColumnModel().getColumn(2).setPreferredWidth(50);
    tb_fechado.getColumnModel().getColumn(2).setPreferredWidth(50);
    tb_fechado.getColumnModel().getColumn(2).setPreferredWidth(50);
    
    
    DefaultTableModel tabela = (DefaultTableModel)tb_fechado.getModel();
    tabela.setNumRows(0);
    
    try
    {
         
        con_servf.resultset.beforeFirst();
         
        while(con_servf.resultset.next())
        {
            
            tabela.addRow(new Object[]{con_servf.resultset.getString("codcall"),con_servf.resultset.getString("nsetor"),con_servf.resultset.getString("nmaq"),con_servf.resultset.getString("tipop"),con_servf.resultset.getString("usuario"),con_servf.resultset.getString("data")});
                
        }
        con_servf.resultset.first();
    }
    catch(SQLException erro)
    {        
        JOptionPane.showMessageDialog(null,"Erro ao listar os dados na tabela "+erro);    

    } */   
    
}//GEN-LAST:event_bt_mostraActionPerformed

private void bt_visuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_visuActionPerformed

       
  
              
        try {
            
                  
            
            
            int linha = tb_aberto.getSelectedRow(); //cria uma variável (linha) do tipo integer para receber o valor da linha selecionada no JTable
            if(linha  < 0 )
            {
                               
                new hd_server().setVisible(true);
                con_hdserver.executasql("select * from helpdeska");
                con_hdserver.resultset.first();
                hd_server.mostrar_dados();
                
                if(hd_server.lb_ncall.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Não há nenhum chamado em aberto!");
            hd_server.bt_primeiro.setEnabled(false);
            hd_server.bt_anterior.setEnabled(false);
            hd_server.bt_proximo.setEnabled(false);
            hd_server.bt_ultimo.setEnabled(false);
            hd_server.bt_atender.setEnabled(false);
            hd_server.bt_gravar.setEnabled(false);
            hd_server.bt_trocar.setEnabled(false);
            hd_server.jm_troca.setEnabled(false);
            hd_server.jm_salvar.setEnabled(false);
            hd_server.jm_atend.setEnabled(false);
        }
                
                
                return;
            }
            else
            {
            TableModel modelo = (TableModel) tb_aberto.getModel(); //cria uma variável (modelo) do tipo TableModel para poder tratar os dados que estão na tabela
            String cod =(String) modelo.getValueAt(linha,0); //variável cod recebe o código que está no jtable na linha selecionada 
            
            if(cod == null )
            {
                new hd_server().setVisible(true);
                con_hdserver.executasql("select * from helpdeska");
                con_hdserver.resultset.first();
                hd_server.mostrar_dados();
                return;
            }
            
            con_aberto.executasql("select * from helpdeska where codcalla="+cod); //seleciona o registro com o mesmo código que o do JTable
            con_aberto.resultset.first();
            
            
            
                     
            
            new hd_server().setVisible(true);
            //con_hdserver.executasql("select * from helpdeska where codcalla="+cod); //seleciona o registro com o mesmo código que o do JTable
            //con_hdserver.resultset.first();
            con_hdserver.executasql("select * from helpdeska");
            con_hdserver.resultset.beforeFirst();
            //new hd_server().setVisible(true);
            while(con_hdserver.resultset.next())
            {
                if(con_hdserver.resultset.getString("codcalla").equals(cod))
                {
                 hd_server.mostrar_dados();
                 break;
                }
                else
                {
                    continue;
                }
            }
            
            
          
            /*hd_server.lb_ncall.setText(con_aberto.resultset.getString("codcalla"));
            hd_server.lb_setor.setText(con_aberto.resultset.getString("nsetora"));
            hd_server.lb_nmaq.setText(con_aberto.resultset.getString("nmaqa"));
            hd_server.lb_ip.setText(con_aberto.resultset.getString("ipmaqa"));
            hd_server.lb_tipop.setText(con_aberto.resultset.getString("tipopa"));
            hd_server.ta_obs.setText(con_aberto.resultset.getString("descpa"));
            hd_server.lb_nuser.setText(con_aberto.resultset.getString("usuarioa"));
            hd_server.lb_status.setText(con_aberto.resultset.getString("status"));
            hd_server.lb_tecresp.setText(con_aberto.resultset.getString("tecnicoa"));
            //hd_server.lb_dataab.setText(con_aberto.resultset.getString("dataab"));*/
       
            
            
            }
        } 
        catch (SQLException ex) {
            Logger.getLogger(hd_principal.class.getName()).log(Level.SEVERE, null, ex);
        }
           
}//GEN-LAST:event_bt_visuActionPerformed

private void bt_atualizaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_atualizaActionPerformed

    con_server.executasql("select * from helpdeska order by status,codurgencia,ordem");
    preencher_tabela();
    
}//GEN-LAST:event_bt_atualizaActionPerformed

private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime

    
    con_server.executasql("select * from helpdeska order by status , codurgencia , ordem");
    preencher_tabela();
     
       
    
}//GEN-LAST:event_timer1OnTime

private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified

     stray();
       
    
}//GEN-LAST:event_formWindowIconified

private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified

    
    
}//GEN-LAST:event_formWindowDeiconified

private void timer2OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer2OnTime
        
    
       
 trayIcon.displayMessage("Atenção!","Você tem "+linhas+" chamados abertos!",
        TrayIcon.MessageType.INFO);
       
       
        

       
    
}//GEN-LAST:event_timer2OnTime

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

                
    try
            {
                con_pesq.executasql("select * from helpdeska order by status,codurgencia,ordem");
                con_pesq.resultset.beforeFirst();
                JRResultSetDataSource jrrs = new JRResultSetDataSource(con_pesq.resultset);
                JasperPrint jspimp = JasperFillManager.fillReport("relatórios/rel_helpa.jasper", new HashMap(),jrrs);
                JasperViewer.viewReport(jspimp,false);

            }
            catch(Exception erro)
            {
                JOptionPane.showMessageDialog(null, "erro ="+erro);
            }     
    
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed

    new rel_help().setVisible(true);
    
}//GEN-LAST:event_jMenuItem6ActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

      bt_visuActionPerformed(evt);
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

    bt_atualizaActionPerformed(evt);
    
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed

    bt_mostraActionPerformed(evt);
    
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed

    setVisible(false);
    
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

     DefaultTableModel tableModel =(DefaultTableModel) tb_fechado.getModel();  
    tableModel.setNumRows(0);
    
}//GEN-LAST:event_jButton1ActionPerformed

private void jm_voltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_voltarActionPerformed
    
        try {
            
            con_user.executasql("select * from login where nome like'"+lb_tec.getText()+"'");
            con_user.resultset.first();
            acesso = con_user.resultset.getString("acesso"); 
        } 
        catch (SQLException ex) {
            Logger.getLogger(hd_principal.class.getName()).log(Level.SEVERE, null, ex);
        }
      
    new tela_principal().setVisible(true);
    
    tela_principal.lbusuario.setText(lb_tec.getText());
    tela_principal.lbnivel.setText(acesso);
    tela_principal.bt_helps.setEnabled(false);
    tela_principal.lb_helps.setVisible(false);
    tela_principal.jm_helps.setEnabled(false);
    
    jm_voltar.setEnabled(false);
}//GEN-LAST:event_jm_voltarActionPerformed

private void tb_fechadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tb_fechadoMouseClicked

    if (evt.getClickCount() ==1) 
{
    
      
           
    int linha = tb_fechado.getSelectedRow(); //cria uma variável (linha) do tipo integer para receber o valor da linha selecionada no JTable
    TableModel modelo = (TableModel) tb_fechado.getModel(); //cria uma variável (modelo) do tipo TableModel para poder tratar os dados que estão na tabela
    String cod =(String) modelo.getValueAt(linha,0); //variável cod recebe o código que está no jtable na linha selecionada 
    
    if(cod == null )
    {
        return;
    }
    
try 
{
      
      con_fecha.resultset.beforeFirst();
      
      tb_fechado.setVisible(false);
      
      new hd_fechados().setVisible(true);
           
      while(con_fecha.resultset.next())
            {
                if(con_fecha.resultset.getString("codcall").equals(cod))
                {
                 hd_fechados.mostrar_dados();
                 break;
                }
                else
                {
                    continue;
                }
            }
      
                
    } 
catch (SQLException ex) 
{
                Logger.getLogger(cad_maq.class.getName()).log(Level.SEVERE, null, ex);
}




       
}    
}//GEN-LAST:event_tb_fechadoMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new hd_principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_atualiza;
    private javax.swing.JButton bt_mostra;
    public static javax.swing.JButton bt_visu;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    public static javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    public static javax.swing.JMenuItem jm_voltar;
    public static javax.swing.JLabel lb_tec;
    private javax.swing.JTable tb_aberto;
    public static javax.swing.JTable tb_fechado;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    private org.netbeans.examples.lib.timerbean.Timer timer2;
    // End of variables declaration//GEN-END:variables

    public void preencher_tabela()
{
   
    tb_aberto.getColumnModel().getColumn(0).setPreferredWidth(10);
    tb_aberto.getColumnModel().getColumn(1).setPreferredWidth(130);
    tb_aberto.getColumnModel().getColumn(2).setPreferredWidth(60);
    tb_aberto.getColumnModel().getColumn(3).setPreferredWidth(80);
    tb_aberto.getColumnModel().getColumn(4).setPreferredWidth(90);
    tb_aberto.getColumnModel().getColumn(5).setPreferredWidth(50);
    tb_aberto.getColumnModel().getColumn(6).setPreferredWidth(30);
    
    DefaultTableModel tabela = (DefaultTableModel)tb_aberto.getModel();
    tabela.setNumRows(0);
    
    try
    {
         
        con_server.resultset.beforeFirst();
         
        while(con_server.resultset.next())
        {
            
            tabela.addRow(new Object[]{con_server.resultset.getString("codcalla"),con_server.resultset.getString("nsetora"),con_server.resultset.getString("nmaqa"),con_server.resultset.getString("tipopa"),con_server.resultset.getString("status"),con_server.resultset.getString("urgenciaa"),con_server.resultset.getString("ordem")});
                
        }
        con_server.resultset.first();
    }
    catch(SQLException erro)
    {        
        JOptionPane.showMessageDialog(null,"Erro ao listar os dados na tabela "+erro);    

    }  
    DefaultTableModel tab = (DefaultTableModel)tb_aberto.getModel();
    linhas = tab.getRowCount();
}
    public void lookandfeel()
     
    {
             
         try
        {
            //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
            //UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            UIManager.setLookAndFeel(seta_look);
            SwingUtilities.updateComponentTreeUI(this);
            
        }        
        catch(Exception erro)
        {
            JOptionPane.showMessageDialog(null,erro);
        
        } 
        }   
    
  public void stray()
        {
            setVisible(false);
            //final TrayIcon trayIcon ;
         if (cont == 0)
     {
         
         
           
        if (SystemTray.isSupported()) {

        /*final SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("C:/Documents and Settings/Shinigami/Meus documentos/NetBeansProjects/helpdesk/src/imagens/rocket.gif");*/
       
       /* ActionListener exitListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        System.out.println("Exiting...");
        System.exit(0);
        }
        };*/
        
        /*PopupMenu popup = new PopupMenu();
        MenuItem defaultItem = new MenuItem("Exit");*/
        defaultItem.addActionListener(exitListener);
        popup.add(defaultItem);
        
//        trayIcon = new TrayIcon(image, "Help Desk!", popup);
        
        MouseListener mouseListener = new MouseListener() {
        
        public void mouseClicked(MouseEvent e) {
        setVisible(true);
        setState(0);
        

        //System.out.println("Tray Icon - Mouse clicked!");
        }

        public void mouseEntered(MouseEvent e) {
        
        //System.out.println("Tray Icon - Mouse entered!");
        }

        public void mouseExited(MouseEvent e) {

        //System.out.println("Tray Icon - Mouse exited!");
        }

        public void mousePressed(MouseEvent e) {
        //System.out.println("Tray Icon - Mouse pressed!");
        }

        public void mouseReleased(MouseEvent e) {
        //System.out.println("Tray Icon - Mouse released!");
        }


                    };

        /*ActionListener exitListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        System.out.println("Exiting...");
        System.exit(0);
        }
        };*/

        /*PopupMenu popup = new PopupMenu();
        MenuItem defaultItem = new MenuItem("Exit");
        defaultItem.addActionListener(exitListener);
        popup.add(defaultItem);*/


//        trayIcon = new TrayIcon(image, "Help Desk!", popup);
        
         ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        trayIcon.displayMessage("Atenção!","Você tem "+linhas+" chamados abertos!",
        TrayIcon.MessageType.INFO);
        }
        };

        trayIcon.setImageAutoSize(true);
        trayIcon.addActionListener(actionListener);
        trayIcon.addMouseListener(mouseListener);

        try {
        tray.add(trayIcon);
        } catch (AWTException x) {
        System.err.println("TrayIcon could not be added.");
        }

        } else {

        // System Tray is not supported
        
        } 
        cont = 1;
     }
            
        }
    
    ActionListener exitListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        System.out.println("Exiting...");
        
        tela_principal.bt_helps.setEnabled(true);
        tela_principal.lb_helps.setVisible(true);
        tela_principal.jm_helps.setEnabled(true);
        
        System.exit(0);
        }
        };
        
       
}
